home *** CD-ROM | disk | FTP | other *** search
- Path: yarrow.wt.com.au!usenet
- From: bvarley@yarrow.wt.com.au (bruce varley)
- Newsgroups: comp.lang.c
- Subject: Reclaiming memory allocated recursively
- Date: Tue, 02 Jan 1996 02:52:35 GMT
- Organization: Winthrop Technology
- Message-ID: <4c8f8q$ln9@yarrow.wt.com.au>
- NNTP-Posting-Host: yarrow
- X-Newsreader: Forte Free Agent 1.0.82
-
- I'm using self-referential structures as described in K&R 6.5 (page
- 130 in my version). The program runs 'forever', storing data in a
- binary tree - a days worh of data is collected, then dumped, and the
- whole process starts all over again. My question is: How can I
- reclaim the memory that has been recursively allocated? Using the
- same approach as creating the tree - ie..........
-
- struct node *freetree (struct node *p)
- {
- if (p != NULL)
- {
- freetree (p -> left) ;
- free (p -> data_pointer) ;
- freetree (p -> right) ;
- }
- return (0) ;
- }
-
- seems unlikely to work, because the memory required to navigate
- through the tree is being deallocated as the process proceeds. In
- fact, the system crashes when I run the routine.
-
- Any assistance would be most appreciated.
-
- bvarley@yarrow.wt.com.au
-
-